<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>RSA加密</title>
    <script type="text/javascript" src="../js/security.js"></script>
    <script type="text/javascript" src="../js/jquery-1.4.js"></script>
    <script>
        var password = '', exponent = '', modulus = '', encrypedPwd = '';

        function checkStr(str) {
            return str != null && str.length > 0;
        }

        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        password = getQueryString("password");
        exponent = getQueryString("exponent");
        modulus = getQueryString("modulus");
        encrypedPwd = getQueryString("encrypedPwd");

        if (checkStr(password) && checkStr(exponent) && checkStr(modulus)) {
            var key = RSAUtils.getKeyPair(exponent, '', modulus);
            var reversedPwd = password.split("").reverse().join("");
            encrypedPwd = RSAUtils.encryptedString(key, reversedPwd);
            $(function () {
                var data = {
                    'result': true,
                    password: password,
                    exponent: exponent,
                    modulus: modulus,
                    encrypedPwd: encrypedPwd
                };
                $("#show").html(JSON.stringify(data));
                $("#show").html(JSON.stringify(data, null, 4));
            });
        } else {
            $(function () {
                var data = {
                    'result': false,
                    msg: "参数不完整"
                };
                $("#show").html(JSON.stringify(data));
                $("#show").html(JSON.stringify(data, null, 4));
            });
        }
    </script>
</head>
<body>
<div>
    <pre id="show">
    </pre>
</div>
</body>
</html>
